$(document).ready(function(){
	
	localStorage.clear();

	
	$("#calculation_method").change(function(){
		var selectedValue=$(this).val();
		if(selectedValue==1){
			$('.total_price').hide()
		}
		else $('.total_price').show()
	})
	
	
	 $("#price").change(function(){
    		var dq_price = Number($('#price').val());
    		var dq_proportion  = $('#proportion').val();
    		$('#price2').val(parseFloat(dq_price*dq_proportion).toFixed(2));
  	});
  	$('#price2').change(function(){
  		if($("#price").val()!=0 && $("#price").val()!=""){
  			var dq_price = Number($('#price').val());
    		var dq_proportion  = $('#proportion').val();
    		$('#price2').val(parseFloat(dq_price*dq_proportion).toFixed(2));
  			
  		}
  			
  	})
  	$("#proportion").change(function(){
    		var dq_price = Number($('#price').val());
    		var dq_proportion  = $('#proportion').val();
    		$('#price2').val(parseFloat(dq_price*dq_proportion).toFixed(2));
  	});
  	 $('.rmb_input').blur('input',function(){
  	 	
  	 		if(!isPInt($(this).val())){
  	 			$(this).val("");
  	 		}
  	 		
  	 })
  	 function isPInt(str) {//是否是正整数
    	var g = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
    	return g.test(str);
	}
	$("#year2").change(function(){
		
		if($(this).val()>5){
			
			$("#lending_rate").empty().append('<option value="0.0325">公积金基准利率1倍（3.25%）</option><option value="0.03575">公积金基准利率1.1倍</option><option value="0.039">公积金基准利率1.2倍</option>')
		}else{
			$("#lending_rate").empty().append('<option value="0.0275">公积金基准利率1倍（2.75%）</option><option value="0.03025">公积金基准利率1.1倍</option><option value="0.033">公积金基准利率1.2倍</option>')
		}
		
		
	})
	
	
	
	$('.calculation_button').click(function(){
		window.location.replace("../calculation_results/计算结果.html");
		
		var lending_rate = $('#lending_rate').val(); //贷款利率
		var price = $('#price').val();  //房价总额
		var pric2 = $('#price2').val();  //贷款总额
		var proportion  = $('#proportion').val();  //贷款比例
		var year2  = $('#year2').val();  //贷款年限
		 localStorage.setItem("lending_rate", lending_rate);
		 localStorage.setItem("price", price);
		 localStorage.setItem("pric2", pric2);
		 localStorage.setItem("proportion", proportion);
		 localStorage.setItem("year2", year2);
		 localStorage.setItem("mortgage_Calculator", 1);
	})
	
})